<template>
  <div class="orders-content">
    <cube-scroll ref="scroll" class="orders" :options="scrollOptions">
      <order-select
        @select="onSelect"
        @toggle="onToggle"
        :selectType="selectType"
        :onlyContent="onlyContent"
        :orders="orders"
      >
      </order-select>
      <div class="order-wrapper">
        <ul>
          <li
            v-for="(order,index) in computedOrders"
            :key="index"
            class="order-item border-bottom-1px"
            @click="showOrderDetail(order)"
          >
            <div class="avatar">
              <!-- <img width="28" height="28" :src="order.avatar"> -->
              <img width="28" height="28" src="http://static.galileo.xiaojukeji.com/static/tms/default_header.png">
            </div>
            <div class="content">
              <h1 class="name">{{order.buyerName}}</h1>
              <div class="time">
                {{format(order.createTime)}}
              </div>
            </div>
          </li>
        </ul>
      </div>
    </cube-scroll>
  </div>

</template>

<script>
  import Star from 'components/star/star'
  import OrderSelect from 'components/order/order-select'
  import Split from 'components/split/split'
  import orderMixin from 'common/mixins/order'
  import { getOrderList, getCookie } from 'api'

  export default {
    name: 'orders',
    mixins: [orderMixin],
    props: {
      data: {
        type: Object
      }
    },
    data () {
      return {
        orderList: [],
        orders: []
      }
    },
    computed: {
      seller () {
        return this.data.seller || {}
      }
    },
    mounted() {
      this.init()
    },
    methods: {
      init() {
        getOrderList({
          openid: getCookie('openid'),
          page: 0,
          size: 100
        }).then((orders) => {
          this.orders = orders
        })
      },
      format (time) {
        var date = new Date(time * 1000)
        return date.getFullYear() +
          '-' +
          (date.getMonth() + 1) +
          '-' +
          date.getDate() +
          ' ' +
          date.getHours() +
          ':' +
          date.getMinutes()
      },
      showOrderDetail (item) {
        this.$router.push({ path: `/order/${item.orderId}` })
      }
    },
    components: {
      Star,
      Split,
      OrderSelect
    },
    watch: {
      selectType () {
        this.$nextTick(() => {
          this.$refs.scroll.refresh()
        })
      }
    }
  }
</script>

<style lang="stylus" scoped>
  @import "~common/stylus/variable"
  @import "~common/stylus/mixin"

  .orders
    position: fixed
    z-index: 100
    top: 0
    left: 0
    width: 100%
    height: 100%
    text-align: left
    white-space: normal
    background-color: #f5f5f5
    .overview
      display: flex
      padding: 18px 0
      .overview-left
        flex: 0 0 137px
        padding: 6px 0
        width: 137px
        border-right: 1px solid $color-col-line
        text-align: center
        @media only screen and (max-width: 320px)
          flex: 0 0 120px
          width: 120px
        .score
          margin-bottom: 6px
          line-height: 28px
          font-size: $fontsize-large-xxx
          color: $color-orange
        .title
          margin-bottom: 8px
          line-height: 12px
          font-size: $fontsize-small
          color: $color-dark-grey
        .rank
          line-height: 10px
          font-size: $fontsize-small-s
          color: $color-light-grey
      .overview-right
        flex: 1
        padding: 6px 0 6px 24px
        @media only screen and (max-width: 320px)
          padding-left: 6px
        .score-wrapper
          display: flex
          align-items: center
          margin-bottom: 8px
          .title
            line-height: 18px
            font-size: $fontsize-small
            color: $color-dark-grey
          .star
            margin: 0 12px
          .score
            line-height: 18px
            font-size: $fontsize-small
            color: $color-orange
        .delivery-wrapper
          display: flex
          align-items: center
          .title
            line-height: 18px
            font-size: $fontsize-small
            color: $color-dark-grey
          .delivery
            margin-left: 12px
            font-size: $fontsize-small
            color: $color-light-grey
    .order-wrapper
      padding: 0 18px
      .order-item
        display: flex
        padding: 18px 0
        &:last-child
          border-none()
        .avatar
          flex: 0 0 28px
          width: 28px
          margin-right: 12px
          img
            height: auto
            border-radius: 50%
        .content
          position: relative
          flex: 1
          .name
            margin-bottom: 4px
            line-height: 12px
            font-size: $fontsize-small-s
            color: $color-dark-grey
          .star-wrapper
            margin-bottom: 6px
            display: flex
            align-items: center
            .star
              margin-right: 6px
            .delivery
              font-size: $fontsize-small-s
              color: $color-light-grey
          .text
            margin-bottom: 8px
            line-height: 18px
            color: $color-dark-grey
            font-size: $fontsize-small
          .recommend
            display: flex
            align-items: center
            flex-wrap: wrap
            line-height: 16px
            .icon-thumb_up, .item
              margin: 0 8px 4px 0
              font-size: $fontsize-small-s
            .icon-thumb_up
              color: $color-blue
            .item
              padding: 0 6px
              border: 1px solid $color-row-line
              border-radius: 1px
              color: $color-light-grey
              background: $color-white
          .time
            position: absolute
            top: 0
            right: 0
            line-height: 12px
            font-size: $fontsize-small
            color: $color-light-grey
</style>
